/*
 * @Description: 
 * @Author: liyuhao
 * @Date: 2021-07-12 15:16:24
 * @LastEditors: liyuhao
 * @LastEditTime: 2021-07-23 10:28:25
 */
import React from 'react'
import { Button, Spin } from 'antd'
import { LoadingOutlined } from '@ant-design/icons'
import { SpinProps } from 'antd/lib/spin'
import { ButtonProps } from 'antd/lib/button'

type _SpinProps = Pick<SpinProps, 'indicator' | 'wrapperClassName'>
interface _ButtonProps extends Omit<ButtonProps, 'loading'> {
  loading?: boolean
}

export type SpinButtonProps = _SpinProps & _ButtonProps

const defaultIcon = <LoadingOutlined style={{ fontSize: 20 }} spin />

// 主要用于处理link button的loading状态
const SpinButton: React.FC<SpinButtonProps> = props => {
  const { loading, indicator, children, wrapperClassName, ...buttonProps } = props

  return (
    <Spin spinning={!!loading} indicator={indicator || defaultIcon} wrapperClassName={wrapperClassName}>
      <Button {...buttonProps}>{children}</Button>
    </Spin>
  )
}

export default SpinButton